//
//  WYNavigationController.swift
//  Weibo
//
//  Created by Mr.Run on 2016/11/19.
//  Copyright © 2016年 Mr.Run. All rights reserved.
//

import UIKit

class WYNavigationController: UINavigationController {
    
    
    override func viewDidLoad() {
        
        navigationBar.isHidden = true
        
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0{
            
            viewController.hidesBottomBarWhenPushed = true
            if let vc = viewController as? WYBaseViewController{
                var title = "返回"
                if viewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent), isBack: true)
                
            }
            
        }
        super.pushViewController(viewController, animated: true)
    }
    
    @objc fileprivate func popToParent(){
         popViewController(animated: true)
    }
    
}
